package com.example.shopping.controller;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 测试-redis集群
 */
@RequestMapping("/testRedisCluster")
@RestController
public class TestRedisClusterController {

    @Resource
    private RedisTemplate redisTemplate;


    @GetMapping("/setRedisData")
    public void setRedisData(@RequestParam String key, @RequestParam Object val) {
        redisTemplate.opsForValue().set(key, val);
    }

    @GetMapping("/getRedisData")
    public String getRedisData(@RequestParam String key) {
        Object o = redisTemplate.opsForValue().get(key);
        return key + "->" + o;
    }


}
